﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BuySoftwareOnline.Domain.Abstract;

namespace BuySoftwareOnline.Domain.Concrete
{
    public class CategoryRepository : ICategoryRepository
    {
        private BuySoftwareOnlineDataContext context;

        public CategoryRepository()
        {
            context = new BuySoftwareOnlineDataContext();
        }

        public IQueryable<Category> Categories
        {
            get { return context.Categories; }
        }

        public void SaveCategory(Category category)
        {
            if (category.CategoryID == 0)
            {
                context.Categories.InsertOnSubmit(category);
            }
            else
            {
                context.Categories.Attach(category);
                context.Refresh(System.Data.Linq.RefreshMode.KeepCurrentValues, category);
            }
            context.SubmitChanges();
        }

        public void DeleteCategory(Category category)
        {
            context.Categories.DeleteOnSubmit(category);
            context.SubmitChanges();
        }
    }
}
